package com.imooc.controller;

import com.imooc.handler.JSONResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("teacher")
@RefreshScope       // Nacos配置中心动态刷新配置的注解
public class HelloController {

    @Value("${server.port}")
    private String port;

    @GetMapping(value = "/hello") //, produces = MediaType.APPLICATION_JSON_VALUE)
    public JSONResult hello() {

//        try {
//            Thread.sleep(300);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

//        int a = 1 / 0;

        System.out.println("port:" + port);
        return JSONResult.ok("Hello Teacher~");
    }

    @Value("${alibaba.teacher.name}")
    private String name;
    @Value("${alibaba.teacher.age}")
    private Integer age;

    @GetMapping("/info")
    public Object info() {
        return name + " - " + age;
    }
}
